package com.stylefeng.guns.modular.party.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.SpEmploye;
import com.stylefeng.guns.modular.party.service.ISpEmployeService;

/**
 * 雇员控制器
 *
 * @author fengshuonan
 * @Date 2018-12-02 13:48:51
 */
@Controller
@RequestMapping("/spEmploye")
public class SpEmployeController extends BaseController {

    private String PREFIX = "/party/spEmploye/";

    @Autowired
    private ISpEmployeService spEmployeService;

    /**
     * 跳转到雇员首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "spEmploye.html";
    }

    /**
     * 跳转到添加雇员
     */
    @RequestMapping("/spEmploye_add")
    public String spEmployeAdd() {
        return PREFIX + "spEmploye_add.html";
    }

    /**
     * 跳转到修改雇员
     */
    @RequestMapping("/spEmploye_update/{spEmployeId}")
    public String spEmployeUpdate(@PathVariable Integer spEmployeId, Model model) {
        SpEmploye spEmploye = spEmployeService.selectById(spEmployeId);
        model.addAttribute("item",spEmploye);
        LogObjectHolder.me().set(spEmploye);
        return PREFIX + "spEmploye_edit.html";
    }

    /**
     * 获取雇员列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return spEmployeService.selectList(null);
    }

    /**
     * 新增雇员
     */
    @ApiOperation("新增雇员")
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public Object add(SpEmploye spEmploye) {
        spEmployeService.insert(spEmploye);
        return SUCCESS_TIP;
    }

    /**
     * 删除雇员
     */
    @ApiOperation("删除雇员")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Object delete(@RequestParam Integer spEmployeId) {
        spEmployeService.deleteById(spEmployeId);
        return SUCCESS_TIP;
    }

    /**
     * 修改雇员
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SpEmploye spEmploye) {
        spEmployeService.updateById(spEmploye);
        return SUCCESS_TIP;
    }

    /**
     * 雇员详情
     */
    @RequestMapping(value = "/detail/{spEmployeId}")
    @ResponseBody
    public Object detail(@PathVariable("spEmployeId") Integer spEmployeId) {
        return spEmployeService.selectById(spEmployeId);
    }
}
